package com.sskj.mine.presenter;

import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;

import com.sskj.mine.bean.RecordsBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.fragment.AssetFragment;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Flowable;


/**
 * @author Hey
 * Create at  2019/05/18
 */
public class AssetPresenter extends BasePresenter<AssetFragment> {
    /**
     * 充值/提币记录
     *
     * @param type recharge 充值 cash 提币
     * @return
     */
    public Flowable<List<RecordsBean>> getAssetRecord(String type, String p, String size) {
        return httpService.getAssetRecord(type, p, size)
                .converter(new JsonConverter<HttpData<PageBean<RecordsBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(pageBeanHttpData -> pageBeanHttpData.getData().getList())
                .onErrorReturnItem(new ArrayList<>());
    }

    public void cancelTibi(String id) {
        httpService.cancelTibi(id)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.cancelSuccess();
                        }
                    }
                });
    }
}
